from django.test import TestCase

class FanwenAPITests(TestCase):

    def setUp(self):
        print("=====Test fanwen API ========")
        self.token = "b645626e4f6c11e9a725e0d55eb04500"

    def test_fanwen_news(self):
        number = 4
        res = self.client.get(
            '/fsp_toutiao',
            {
                'id': '6934',
                'num': number,
            }
        )

        self.assertEqual(200, res.status_code)

        result = res.json()
        self.assertTrue(result['Succeed'])
        self.assertEqual(number, len(result['obj']['rows']))


    def test_fanwen_stat(self):
        res = self.client.get('/fsp_statistics')

        self.assertEqual(200, res.status_code)

        result = res.json()
        self.assertIsNotNone(result.get('total'))


    def test_fanwen_diffusion(self):
        number = 4
        res = self.client.get(
            '/fsp_fsnews',
            {
                'num':number
            }
        )

        self.assertEqual(200, res.status_code)

        result = res.json()
        self.assertEqual(number, len(result['obj']['rows']))